Unit CalNVC;

Interface

uses EXTDR,ADC,Crt,Dos,Graph,GlobVar,show,escreva;


Procedure Cal0;
Procedure Cal1;
Procedure Cal2;
Procedure Cal3;
Procedure DefineCalibracaoY;
Procedure DefineGanho;
Procedure Escalas;
Procedure AumentaY;
Procedure CorrigeY;
Procedure DiminueY;
Procedure AumentaX;
Procedure DiminueX;
Procedure AumentaGanho;
Procedure DiminueGanho;
Procedure AumentaCanal;
Procedure DiminueCanal;
Procedure AumentaDuration;
Procedure DiminueDuration;
Procedure AumentaRate;
Procedure DiminueRate;
Procedure TrocaDuration;
Procedure TrocaEscalaX;
Procedure Trocarate;
Procedure TrocaEscalaY;
Procedure TrocaCanal;
Procedure MudaEscalaY;
Procedure MudaX;
Procedure ChangeX;
Procedure MudaY;
Procedure ApagaOpcao;
Procedure MarcaOpt(st  :  string);

Implementation

Procedure ApagaOpcao;

begin
     SetViewPort(0,0,GetMaxX,GetMaxY,true);
     setFillStyle(11,9);
     bar(PosX+2,400,PosX+220,412);
     setviewport(InitX,InitY,FinX,FinY,true);
     setcolor(15);
     setfillstyle(1,0);
end;

Procedure MarcaOpt(st  :  string);

begin
     setFillStyle(11,9);
     setcolor(14);
     writeText(PosX+2,400,st);
     setcolor(15);
     setfillstyle(1,0);
end;

Procedure cal0;

const  cal : array [1..16] of integer =  (1,1,1,1,1,3,7,14,35,70,140,350,700,1400,3500,7000);
{const  cal : array [1..16] of integer = (1,2,5,10,20,50,100,200,500,1000,2000,5000);}

var      k : integer;

begin
     for k:=1 to 16 do calY[k]:= cal[k];
end;


Procedure cal1;

const  cal : array [1..16] of integer =  (1,1,1,1,3,7,14,28,70,140,280,700,1400,2800,7000,14000);

{const cal : array [1..16] of integer =  (1,1,3,6,12,30,60,120,300,600,1200,3000);}

var      k : integer;

begin
     for k:=1 to 16 do calY[k]:= cal[k];
end;

Procedure cal2;

const  cal : array [1..16] of integer =   (1,2,3,7,14,35,70,140,350,700,1400,2800,3500,7000,14000,28000);
{const  cal : array [1..12] of integer =  (3,6,15,30,60,150,300,600,1500,3000,6000,15000);}
var      k : integer;

begin
     for k:=1 to 16 do calY[k]:= cal[k];
end;


Procedure cal3;                          {----1--2----3--4-5-6--7-8-9-10--11--12--13--14--15-16 }
                                         {---100,200,500,1,2,5,10,20,50,100,200,500,1,2,5,10---}
const  cal : array [1..16] of integer =    (7,14,35,70,140,240,350,700,1400,2800,16000,16000,16000,16000,16000,16000);
{const  cal : array [1..16] of integer =  (30,60,150,300,600,1500,3000,6000,15000,30000,30000,3000);}

var      k : integer;

begin
     for k:=1 to 16 do calY[k]:= cal[k];
end;

Procedure cal_1;

const  cal : array [1..16] of integer =    (1,1,1,1,1,1,1,1,3,7,14,35,70,140,350,700);

var      k : integer;

begin
     for k:=1 to 16 do calY[k]:= cal[k];
end;




Procedure MudaY;
begin
   { DefineCalibracaoY;}
    setfillstyle(11,9);
    setcolor(14);
    WriteText(PosX+5*h,TamY-15,Int2Str(calibracao*EscY[IescY]));
       case IescY of
        1..3  :  WriteText(PosX+60,TamY-30,'nV');
        4..12 :  WriteText(PosX+60,TamY-30,'uV');
        12..16:  WriteText(PosX+60,TamY-30,'mV');
      end;
     setcolor(15);
end;

Procedure DefineCalibracaoY;
var
  OldMem :  Integer;

begin
 OldMem:=Imem;
   case ganho of
      -1  :    cal_1;
       0  :    cal0;
       1  :    cal1;
       2  :    cal2;
       3  :    cal3;
     end;
 Imem:=OldMem;
end;


Procedure DefineGanho;
var
  OldMem :  Integer;

begin
  begin
    OldMem:=Imem;
     case IEscY of
     0..3     : ganho:=3;
     4..5     : ganho:=2;
     6..7     : ganho:=1;
     8..9     : ganho:=0;
    10..16    : ganho:=-1;
    else IEscY:=16;
   end;
end;
end;

  Procedure Escalas;

          Begin
               Initx:=239;
               Inity:=120;
               finx:=Initx+365;
               finy:=inity+340;
               Limiar:=1000;
               Postext:=InitX-58;
               IEscY:=8;
               IEscX:=1;

               Irate:=1;
               Iduration:=1;
               m:=2;
               divisor:=1;
               TotalPts:=(EscX[IEscX])*(FinX-InitX) div 20;
               PtInicial:=(finy-inity) div 2;
               Imem:=1;
               DefineCalibracaoY;
          End;

Procedure MudaX;

begin
     setfillstyle(11,9);
     setcolor(14);
     WriteText(PosX,TamY-15,Real1Str(EscX[IEscX]/2));
     setcolor(15);
end;


Procedure AumentaY;
begin
     Mostra;
     case IEscY of
     0..3     :  begin
                 {ganho:=3;}
                 IEscY:=IEscY+1;
              end;
     4..5  :  begin
                 {ganho:=2;}
                 IEscY:=IEscY+1;
              end;
     6..7  :  begin
                 {ganho:=1;}
                 IEscY:=IEscY+1;
              end;
     8..10  :  begin
                 {ganho:=0;}
                 IEscY:=IEscY+1;
              end;
    11..15  :  begin
                 {ganho:=-1;}
                 IEscY:=IEscY+1;
              end;
      else IEscY:=16;
      end;
     Mostra;
     MudaY;
end;


Procedure CorrigeY;
begin
     case IEscY of
     0..3     :  begin
                 {ganho:=3;}
                 IEscY:=IEscY+1;
              end;
     4..5  :  begin
                 {ganho:=2;}
                 IEscY:=IEscY+1;
              end;
     6..7  :  begin
                 {ganho:=1;}
                 IEscY:=IEscY+1;
              end;
    8..9  :  begin
                 {ganho:=0;}
                 IEscY:=IEscY+1;
              end;
    10..16  :  begin
                 {ganho:=-1;}
                 IEscY:=IEscY+1;
              end;
      else IEscY:=16;
      end;
end;

Procedure DiminueY;

begin
     Mostra;
     case IEscY of
     2..4  :  begin
                 {ganho:=3;}
                 IEscY:=IEscY-1;
              end;
     5..7  :  begin
                 {ganho:=2;}
                 IEscY:=IEscY-1;
              end;
    7..8  :  begin
                 {ganho:=1;}
                 IEscY:=IEscY-1;
              end;
   9..10  :  begin
                 {ganho:=0;}
                 IEscY:=IEscY-1;
              end;
   11..16  :  begin
                 {ganho:=-1;}
                 IEscY:=IEscY-1;
              end;
      else IEscY:=1;
      end;
      mostra;
      MudaY;
end;


Procedure AumentaX;

begin
     Mostra;
     If IEscX<6 then IEscX:=IEscX+1
      else IEscX:=6;
     Mostra;
      {WriteText(PosX,TamY-15,Int2Str(EscX[IEscX]));}
      MudaX;
end;

Procedure ChangeX;

begin
     If IEscX<6 then IEscX:=IEscX+1
      else IEscX:=6;
      MudaX;
end;

Procedure DiminueX;

begin
     Mostra;
     If IEscX > 1  then IEscX:=IEscX-1
                         else IescX:=1;
      Mostra;
      {WriteText(PosX,TamY-15,Int2Str(EscX[IEscX]));}
      MudaX;
end;


Procedure AumentaGanho;

begin
     Mostra;
     If Ganho <3 then Ganho:=Ganho+1 else Ganho:=3;
     {WriteText(PosText,InitY+82,Int2Str(ganho));}
     adganho(bd,ganho);
     Mostra;
     {arcaText(PosText,InitY+8*h,Int2Str(ganho));}
end;

Procedure DiminueGanho;

begin
     Mostra;
     If Ganho > 0 then Ganho:=Ganho-1 Else Ganho:=0;
    { WriteText(PosText,InitY+8*h,Int2Str(ganho));}
     adGanho(bd,ganho);
     Mostra;
     {arcaText(PosText,InitY+8*h,Int2Str(ganho));}
end;

Procedure AumentaCanal;

begin
     Mostra;
     If canal<1 then Canal:=Canal+1 else Canal:=1;
     setcolor(14);
     setfillstyle(11,9);
     WriteText(PosX+15*h,TamY-60,Int2str(canal+1));
     adselcanal(bd,canal);
     setcolor(15);
     setfillstyle(1,0);
     Mostra;
end;

Procedure DiminueCanal;

begin
     Mostra;
     If canal > 0 then canal:=canal-1 Else canal:=0;
     setcolor(14);
     setfillstyle(11,9);
     WriteText(PosX+15*h,TamY-60,Int2str(canal+1));
     adselcanal(bd,canal);
     setcolor(15);
     setfillstyle(1,0);
     Mostra;
end;


Procedure AumentaDuration;

begin
      setfillstyle(11,9);
      setcolor(14);
      If IDuration<5 then IDuration:=IDuration+1
      else IDuration:=5;
      SET_PERIODO(IDuration-1);
      WriteText(PosX+15*h,TamY-15,real2str(duration[IDuration]));
      setcolor(15);
      setfillstyle(0,1);
end;

Procedure DiminueDuration;

begin
      setfillstyle(11,9);
      setcolor(14);
     If IDuration > 1  then Iduration:=Iduration-1
                         else Iduration:=1;
     SET_PERIODO(IDuration-1);
     WriteText(PosX+15*h,TamY-15,real2str(duration[IDuration]));
     setcolor(15);
     setfillstyle(0,1);
end;



Procedure AumentaRate;
var
Maxrate : real;

begin
      setfillstyle(11,9);
      setcolor(14);
      If (EscX[IescX]>3) then Maxrate:=(100/EscX[IescX]) else MaxRate:=25;
   if not escapeRp then begin
      If Rate[Irate]<MaxRate then IRate:=IRate+1
      else IRate:=9;
   end else begin
      If Rate[Irate]<MaxRate then IRate:=IRate+1
     {If IRate<5 then IRate:=IRate+1}
      else IRate:=9;
    end;
      if Irate>5 then WriteText(PosX+10*h,TamY-15,real0str(rate[IRate]))
      else  WriteText(PosX+10*h,TamY-15,real2str(rate[IRate]));
      setcolor(15);
      setfillstyle(0,1);
end;

Procedure DiminueRate;

begin
     setfillstyle(11,9);
     setcolor(14);
     If Irate > 0  then Irate:=Irate-1
                         else Irate:=0;
      if Irate>5 then WriteText(PosX+10*h,TamY-15,real0str(rate[IRate]))
      else  WriteText(PosX+10*h,TamY-15,real2str(rate[IRate]));
     setcolor(15);
     setfillstyle(0,1);
end;


Procedure TrocaEscalaX;

const
     Esc    =    #27;
     Ennd   =    #79;
     Rarr   =    #77;
     LArr   =    #75;

var
      teste :  boolean;
begin
   teste:=false;
   setfillstyle(11,9);
   setcolor(14);
   writeText(posX+2,400,' Hor');
   setcolor(15);
     repeat
     ch:=readkey;
      case  ch of
        DArr,LArr      :  DiminueX;
        UArr,RArr      :  AumentaX;
        Ennd      :  Teste:=true;
         #13      :  teste:=true;
        Esc       :  Teste:=True;
      end;
     Until Teste;
     PtInicialX:=60 div EscX[IEscX];
     apagaOpcao;
     setcolor(15);
     setfillstyle(0,1);
end;


Procedure TrocaDuration;


const
     Esc    =    #27;
     UArr   =    #72;
     DArr   =    #80;
     Ennd   =    #79;

var
      teste :  boolean;
begin
   teste:=false;
   setfillstyle(11,9);
   setcolor(14);
   writeText(PosX+2,400,' Dur.');
     repeat
     ch:=readkey;
      case  ch of
        Esc,UArr  :  AumentaDuration;
        Esc,DArr  :  Diminueduration;
        Ennd      :  Teste:=true;
         #13      :  teste:=true;
        Esc       :  Teste:=True;
      end;
     Until Teste;
     apagaopcao;
     setfillstyle(0,1);
     setcolor(15);
end;

Procedure Trocarate;


const
     Esc    =    #27;
     UArr   =    #72;
     DArr   =    #80;
     Ennd   =    #79;

var
      teste :  boolean;
begin
   teste:=false;
   setfillstyle(11,9);
   setcolor(14);
    MarcaOpt('Freq');
    setfillstyle(11,9);
    setcolor(14);
     repeat
     ch:=readkey;
        case  ch of
        Esc,UArr  :  Aumentarate;
        Esc,DArr  :  Diminuerate;
        Ennd      :  Teste:=true;
        #13       :  teste:=true;
        Esc       :  Teste:=True;
      end;
     Until Teste;
     ApagaOpcao;
     setfillstyle(0,1);
     setcolor(15);
end;


Procedure TrocaEscalaY;

const
     Esc    =    #27;
     UArr   =    #72;
     DArr   =    #80;
     Ennd   =    #79;

var
      teste :  boolean;
begin
   MarcaOpt('Vert');
   teste:=false;
     repeat
     ch:=readkey;
      case  ch of
        UArr      :  AumentaY;
        DArr      :  DiminueY;
        #27       :  Halt(0);
        ennd      :  Teste:=true;
        #13       :  teste:=true;
        Esc       :  Teste:=True;
      end;
     Until Teste;
     apagaOpcao;
end;

Procedure TrocaCanal;

const
     Esc    =    #27;
     UArr   =    #72;
     DArr   =    #80;
     Ennd   =    #79;

var
      teste :  boolean;
begin
   teste:=false;
   MarcaOpt('canal');
   setcolor(14);
     setfillstyle(11,9);
     WriteText(PosX+15*h,TamY-60,Int2str(canal+1));
     repeat
     ch:=readkey;
      case  ch of
        Esc,UArr  :  AumentaCanal;
        Esc,DArr  :  DiminueCanal;
        Ennd      :  Teste:=true;
         #13     :  teste:=true;
        Esc       :  Teste:=True;
      end;
     Until Teste;
     ApagaOpcao;
end;

Procedure MudaEscalaY;

var newgain,oldgain   :   integer;

begin
    case ch of
    '1'  :   IEscY:=1;
    '2'  :   IEscY:=2;
    '3'  :   IEscY:=3;
    '4'  :   IEscY:=4;
    '5'  :   IEscY:=5;
    '6'  :   IEscY:=6;
    '7'  :   IEscY:=7;
    '8'  :   IEscY:=8;
    '9'  :   IEscY:=9;
    '0'  :   IEscY:=10;
    end;
   corrigeY;
   MudaY;
   ch:=#13;
end;

end.

